package com.qyhl.module_practice.brand;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeBrandBean;

import java.util.List;

public class PracticeBrandModel implements PracticeBrandContract.PracticeBrandModel {
    private PracticeBrandPresenter mPresenter;

    PracticeBrandModel(PracticeBrandPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String page) {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_BRAND_LIST)
                .params("page", page)
                .params("siteId", CommonUtils.getInstance().getSite()+"")
                .execute(new SimpleCallBack<List<PracticeBrandBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeBrandBean> practiceBrandBeans) {
                        if (practiceBrandBeans != null && practiceBrandBeans.size() > 0) {
                            mPresenter.setList(practiceBrandBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });

    }
}
